-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Bytes
map to Bytes
in SolType
#545
Conversation
d4d2b5c
to
3d080d0
Compare
the original goal of using Couple things:
|
@prestwich Regarding the first point, there's currently a macro_rules! bytes {
() => {
$crate::Bytes::new()
};
($($s:literal)+) => {{
// force const eval
const STATIC_BYTES: &'static [u8] = &$crate::hex!($($s)+);
$crate::Bytes::from_static(STATIC_BYTES)
}};
} For the second point, something that's nice about this is that |
you can add a macro rules arm like this:
|
abc1147
to
e1bd7ca
Compare
Motivation
alloy-sol-types
exposes asol_data::T
variant for each of the primitive types. For example,alloy-primitives::FixedBytes
is represented by analloy-sol-types::FixedBytes
, whose'sSolType
impl points back to the former via the associatedRustType
.In each case
RustType
points back to the alloy primitive, except forBytes
. Currently,Bytes
instead maps toVec<u8>
.This creates issues for encoding & decoding patterns in SDKs like Stylus, which declare traits like.
In particular, we lose the bidirectional relationship the other primitives have. The current work-around in Stylus is to declare a second, incompatible
Bytes
type that implementsSolType
with a correspondingSolValueType
, but this is suboptimal since it's both confusing and not officially supported by Alloy.Solution
The Solution is to make
Bytes
map toBytes
, which it turns out is a very small diff.PR Checklist